package com.blog.cmrpersonalblog.dto.ranking.respnose;

import lombok.Data;

import java.util.List;

/**
 * 榜单分页响应DTO
 * 用于返回分页的榜单数据
 */
@Data
public class RankingPageResponse<T> {

    /**
     * 数据列表
     */
    private List<T> records;

    /**
     * 总记录数
     */
    private Long total;

    /**
     * 当前页码
     */
    private Long current;

    /**
     * 每页大小
     */
    private Long size;

    /**
     * 总页数
     */
    private Long pages;

    /**
     * 是否有下一页
     */
    private Boolean hasNext;

    /**
     * 是否有上一页
     */
    private Boolean hasPrevious;

    /**
     * 构造方法
     */
    public RankingPageResponse() {
    }

    /**
     * 构造方法
     */
    public RankingPageResponse(List<T> records, Long total, Long current, Long size) {
        this.records = records;
        this.total = total;
        this.current = current;
        this.size = size;
        this.pages = (total + size - 1) / size; // 计算总页数
        this.hasNext = current < pages;
        this.hasPrevious = current > 1;
    }

    /**
     * 静态工厂方法
     */
    public static <T> RankingPageResponse<T> of(List<T> records, Long total, Long current, Long size) {
        return new RankingPageResponse<>(records, total, current, size);
    }

    /**
     * 创建简单列表响应（无分页信息）
     */
    public static <T> RankingPageResponse<T> ofList(List<T> records) {
        RankingPageResponse<T> response = new RankingPageResponse<>();
        response.setRecords(records);
        response.setTotal((long) records.size());
        response.setCurrent(1L);
        response.setSize((long) records.size());
        response.setPages(1L);
        response.setHasNext(false);
        response.setHasPrevious(false);
        return response;
    }
}
